import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;

public class FctDivers {

	
	public HashMap<String,Integer> argFctPredefinie = new HashMap<String,Integer>();
	
	public HashMap<String,Method> methodFctPredefinie = new HashMap<String,Method>();
	
	
	public FctDivers() {
		argFctPredefinie.put("invoque", 2);
		argFctPredefinie.put("detaillefct", 1);
		
		
		Class c = FctDivers.class;
		Method[] tab = c.getMethods();
		
		Method  m;
		for (int i=0;i<tab.length;i++) {
			m = tab[i];
	
			if(m.getName().equals("invokeFct"))
				methodFctPredefinie.put("invoque", m);
			
			if(m.getName().equals("fct"))
				methodFctPredefinie.put("detaillefct", m);
			
			
		}    
	};
	
	
	
	public static Object invokeFct(ArrayList<Object> list,  HashMap<String, Object> penv) throws ParseException, Exception{
		ArrayList<Object> v = new ArrayList<Object>();
		
		
		if(list.size() >= 2 && list.get(0) instanceof String)
			if(Bibliotheque.argFctPredefinie.containsKey(list.get(0))) {
				
				for(int i=1;i<list.size();i++) 
					v.add(list.get(i));
			
				Evaluation parser = new Evaluation();
		        parser.initEnv(penv);
		        
				parser.initEnv(penv);

				return (Bibliotheque.methodFctPredefinie.get(list.get(0))).invoke(null,v,penv);
			}
		
		return null;
			}
				

	public static Object fct(ArrayList<Object> list,  HashMap<String, Object> penv) throws ParseException, Exception{
		
		if(list.size() == 1 && list.get(0) instanceof String)
			if(Bibliotheque.stringFctDefinie.containsKey((String)list.get(0)))
				return Bibliotheque.stringFctDefinie.get((String)list.get(0));
			else
				return false;
		else
			return null;
	}
	
}
